<? 
	if(isset($_POST['btnsubmit']))
	{
		require("required/dbconnect.php");
		require("required/share_function.php");
		$bid=$_POST['id'];
		
		restoreInventory($bid);
		
		$update=mysql_query("update os_bill_details set status=-2 where id=$bid");
		header("Location:os_mybill.php");
	}
	require("required/dbconnect.php");
	require("required/share_function.php");
	require("required/header.php");
	require("required/chkuser.php"); 
	require("required/function.php"); 
	
	$bid=$_GET['id'];
	
	$get_bill=mysql_query("select * from os_bill_details where id=$bid and uid=$member_id");
	if(mysql_num_rows($get_bill)==0)
	{
?>
		<script language="javascript">
			window.location="os_invalid.php";
		</script>
<?	
	}
	$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
	if($b['uid']!=$member_id)
	{
		errRedirect(2,"Invalid Access!",$_SERVER['PHP_SELF'],0);	
	}
	$get_item=mysql_query("select * from os_bill_items where bid=$bid")or die("line 11".mysql_error());
?>
		
				<table width="100%">
					
					<tr>
						<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
						<Td align="center" valign="top"> <font style="font-size:14px "><strong>Confirm to cancel the order? </strong></font>
						<br>
						<input type="hidden" value="<?= $bid ?>" name="id">
						<input type="submit" value="Yes" class="button" name="btnsubmit"> <input type="button" value="No" class="button" onClick="history.go(-1)">
						</Td>
						</form>
					</tr>
					<tr>
						<Td>
							<table width="100%" style="border:1px solid red ">
							<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
							<tr>
								<td>
								<table width="100%" cellpadding="0" cellspacing="0">
								<td>Status : <font color="#0066CC"><?= billstatus_eng($b['status']) ?></font></td>
								<td rowspan="2" align="right">
								</td>
								
								</table>
								<table width="100%" bgcolor="#CCCCCC" cellpadding="1" cellspacing="1">
								<tr class="table_header">
									<td width="42%">Product</td><td width="13%">Price(RM)</td><td width="15%">Product code</td><td width="11%">Quantity</td><td width="15%">Total price(RM)</td>
								</tr>
							<?
									$total_item=0;
									$total_piece=0;
									$total_allprice=0;
									$no=1;
									while($c=mysql_fetch_array($get_item))
									{
										$total_price=0;
										$get_product=mysql_query("select * from os_products where id=".$c['pid']);
										$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
										$total_price=$a['price']*$c['quantity'];
										$total_allprice=$total_allprice+$total_price;
										if($no%2==0)
										{
											$class1="table_item_even";
											$class2="table_item_odd";
										}
										else
										{
											$class1="table_item_odd";
											$class2="table_item_even";
										}
																				
							?>
								 <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" onmouseout="this.className='<?= $class1 ?>'" align="center">
									<td><a href="os_view_full.php?id=<?= $c['pid'] ?>"><?= $a['product_name_eng'] ?></a></td><td><?= $c['price'] ?></td><td><?= $a['product_code'] ?></td><td><?= $c['quantity'] ?></td>
									<td align="right"><?= number_format($total_price,2) ?></td>
								</tr>
							<? 
								$no++;
									} 
							?>
							</table></td>
							</tr>
							<tr>
								<td><strong>Order Information</strong></td>
							</tr>
							<tr>
								<td>
								<table width="100%">
								<tr>
								<td width="13%">Order number</td><td width="1%">:</td><td width="29%"><?= $b['invoice_number'] ?>	</td>
								<td width="16%">Order amount</td><td width="1%">:</td><td width="40%"><?= number_format($b['total_amount'],2) ?></td>
								</tr>
								<tr>
								<td width="13%">Order date</td><td width="1%">:</td><td width="29%"><?= $b['create_date'] ?></td>
								<td width="16%">Shipment fees</td><td width="1%">:</td><td width="40%"><?= number_format($b['transport_fees'],2) ?></td>
								</tr>
								<?
									$total_amount=$b['transport_fees']+$b['total_amount']; 
								?>
								<tr>
								<td width="13%"></td><td width="1%"></td><td width="29%"></td>
								<td width="16%">Overall amount</td><td width="1%">:</td><td width="40%"><?= number_format($b['total_amount'],2) ?></td>
								</tr>
								</table>
								</td>
							</tr>
							<tr>
								<td><strong>Receiver Information</strong></td>
							</tr>
							<tr>
								<td>
								<table width="100%">
								<tr>
								<td width="13%">Name</td><td width="1%">:</td><td width="29%"><?= $b['receiver_name'] ?>
								</td>
								<td width="16%">Email</td><td width="1%">:</td><td width="40%"><?= $b['email'] ?>
								</td>
								</tr>
								<tr>
								<td width="13%">Address</td><td width="1%">:</td><td width="29%"><?= $b['address1'] ?>
								</td>
								<td width="16%">Contact number</td><td width="1%">:</td><td width="40%"><?= $b['contact_number'] ?>
								</td>
								<tr>
								<td colspan="2"></td><td width="29%"><?= $b['address2'] ?>
								</td>
								</tr>
								<tr>
								<td width="13%">Postcode</td><td width="1%">:</td><td width="29%"><?= $b['postcode'] ?>
								</td>
								<td width="16%">City</td><td width="1%">:</td><td width="40%"><?= $b['city'] ?>
								</td>
								</tr>
								
								<?
									if($b['state']!=0)
									{
										$get_place=mysql_query("select * from os_state where id=".$b['state'])or die(mysql_error());
										$place=mysql_result($get_place,0,"name_chn");
										$state="$place";
									}
									else
									{
										$state="-";
									}
									
									if($b['country']!=0)
									{
									
										$get_country=mysql_query("select * from os_country where id=".$b['country'])or die(mysql_error());
										$country=mysql_result($get_country,0,"chnname");
										$word_country="$country";
									}
									else
									{
										$word_country="other";
									} 
									
							?>
							<tr>
								<td>State</td><td>:</td><td><?= $state ?></td>
								<td>Country</td><td>:</td><td>
								<?= $word_country ?>
								</td>
							</tr>
							<tr>
								<td>Remark</td><td>:</td><td colspan="4"><?= $b['message'] ?></td>
								
							</tr>
							
								</table>
								</td>
							</tr>
							</form>
							
							</table>
							
						</Td>
					</tr>		  
			  	</table>
<? require("required/footer.php"); ?>	